package com.zhouheng.kafkaproducer.module.basedemo;

import com.zhouheng.kafkacommon.entity.User;
import com.zhouheng.kafkacommon.exception.BaseException;
import com.zhouheng.kafkacommon.util.KafkaUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/producer")
public class producer {

    @Autowired
    private KafkaUtil kafkaUtil;

    @GetMapping("/publishUser")
    public String publishUser(String topics, String name) {
        if(StringUtils.isAnyBlank(topics, name)){
            throw new BaseException("参数异常");
        }
        kafkaUtil.send(topics, new User(name, "美天科技", 12000L));
        return "Published successfully";
    }

    @GetMapping("/publishStr")
    public String publishStr(String topics, String msg) {
        if(StringUtils.isAnyBlank(topics, msg)){
            throw new BaseException("参数异常");
        }
        kafkaUtil.send(topics, msg);
        return "Published successfully";
    }

}
